﻿Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.DAO
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.General
Imports DevComponents.DotNetBar

Public Class frmLoaiTien
    Private m_LoaiTienCtrl As New LoaiTienCtrl()
    Private m_QuyDinh As New QuyDinh()
    Public Sub New()
        InitializeComponent()
        DataService.OpenConnection()
    End Sub

    Private Sub frmLoaiTien_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        m_LoaiTienCtrl.HienThi(DGVDMLoaiTien, BindingNavigatorDMLoaiTien)
    End Sub

    Private Sub bindingNavigatorAddNewItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorAddNewItem.Click
        If DGVDMLoaiTien.RowCount = 0 Then
            BindingNavigatorDMLoaiTien.Enabled = True
        End If
        Dim m_Row As DataRow = m_LoaiTienCtrl.ThemDongMoi()
        m_Row("MaLoaiTien") = ""
        m_Row("LoaiTien") = ""
        m_LoaiTienCtrl.ThemMoi(m_Row)
        BindingNavigatorDMLoaiTien.BindingSource.MoveLast()

    End Sub

    Public Function KiemTraTruocKhiLuu(str As [String]) As [Boolean]
        For Each row As DataGridViewRow In DGVDMLoaiTien.Rows
            If row.Cells(str).Value IsNot Nothing Then
                Dim m_Str As [String] = row.Cells(str).Value.ToString()
                If m_Str = "" Then

                    Return False
                End If
            End If
        Next
        Return True
    End Function

    Private Sub bindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorSaveItem.Click
        If KiemTraTruocKhiLuu("colMaLoaiTien") = True AndAlso KiemTraTruocKhiLuu("colLoaiTien") = True Then
            bindingNavigatorPositionItem.Focus()
            m_LoaiTienCtrl.LuuLoaiTien()
            MessageBoxEx.Show("Đã lưu thành công!", "Hoàn Thành", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBoxEx.Show("Giá trị của ô không được rỗng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End If

    End Sub

    Private Sub bindingNavigatorDeleteItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorDeleteItem.Click
        If DGVDMLoaiTien.RowCount = 0 Then
            bindingNavigatorDeleteItem.Enabled = False

        ElseIf MessageBox.Show("Bạn có chắc chắn xóa dòng này không?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
            BindingNavigatorDMLoaiTien.BindingSource.RemoveCurrent()
        End If

    End Sub

    Private Sub bindingNavigatorCloseItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorCloseItem.Click
        Me.Close()

    End Sub
End Class